home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / irsim / tpos.c < prev    next >
C/C++ Source or Header  |  1993-01-15  |  3KB  |  143 lines

  1. /* 
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     ********************************************************************* 
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include "defs.h"
  17. #include "net.h"
  18. #include "globals.h"
  19.  
  20. #define    HASHSIZE    1021
  21. #define    HN1        1103515245
  22. #define    HN2        12345
  23.  
  24.  
  25. public    int    txt_coords = 0;        /* # of trans. with coordinates */
  26.  
  27. private tptr    tpostbl[ HASHSIZE ];    /* hash table of trans position */
  28.  
  29. private    tptr    other_t = NULL;        /* transistors without coords */
  30. private struct Trans  OtherT;
  31.  
  32.  
  33. #define    UN( N )        ( (Ulong) ( N ) )
  34. #define    HashPos( X, Y )    ( UN( UN( X ) * HN1 + UN( Y ) + HN2 ) % HASHSIZE )
  35.  
  36.  
  37. public void EnterPos( tran, is_pos )
  38.   tptr  tran;
  39.   int   is_pos;
  40.   {
  41.     long  n;
  42.  
  43.     if( is_pos )
  44.       {
  45.     n = HashPos( tran->x.pos, tran->y.pos );
  46.  
  47.     tran->tlink = tpostbl[n];
  48.     tpostbl[n] = tran;
  49.     txt_coords ++;
  50.       }
  51.     else
  52.       {
  53.     if( other_t == NULL )
  54.         other_t = OtherT.x.ptr = OtherT.y.ptr = &OtherT;
  55.     tran->y.ptr = other_t;
  56.     tran->x.ptr = other_t->x.ptr;
  57.     other_t->x.ptr->y.ptr = tran;
  58.     other_t->y.ptr = tran;
  59.     tran->tlink = tran;
  60.       }
  61.   }
  62.  
  63.  
  64. public tptr FindTxtorPos( x, y )
  65.   register long  x, y;
  66.   {
  67.     register tptr  t;
  68.     long           n;
  69.  
  70.     n = HashPos( x, y );
  71.  
  72.     for( t = tpostbl[n]; t != NULL; t = t->tlink )
  73.       {
  74.     if( t->x.pos == x and t->y.pos == y )
  75.         return( t );
  76.       }
  77.     return( NULL );
  78.   }
  79.  
  80.  
  81. public void DeleteTxtorPos( tran )
  82.   tptr  tran;
  83.   {
  84.     register tptr  *t;
  85.     long           n;
  86.  
  87.     n = HashPos( tran->x.pos, tran->y.pos );
  88.  
  89.     for( t = &(tpostbl[n]); *t != NULL; t = &((*t)->tlink) )
  90.       {
  91.     if( *t == tran )
  92.       {
  93.         *t = tran->tlink;
  94.         tran->tlink = tran;
  95.         txt_coords --;
  96.         break;
  97.       }
  98.       }
  99.   }
  100.  
  101.  
  102. public nptr FindNode_TxtorPos( s )
  103.   char  *s;
  104.   {
  105.     long  x, y;
  106.     tptr  t;
  107.  
  108.     if( sscanf( &s[3], "%ld,%ld", &x, &y ) != 2 )
  109.     return( NULL );
  110.  
  111.     if( (t = FindTxtorPos( x, y )) == NULL )
  112.     return( NULL );
  113.  
  114.     switch( s[2] )
  115.       {
  116.     case 'g': return( t->gate );
  117.     case 'd': return( t->drain );
  118.     case 's': return( t->source );
  119.       }
  120.     return( NULL );
  121.   }
  122.  
  123.  
  124. public void walk_trans( func, arg )
  125.   void  (*func)();
  126.   char  *arg;
  127.   {
  128.     register int   index;
  129.     register tptr  t;
  130.  
  131.     for( index = 0; index < HASHSIZE; index++ )
  132.       {
  133.     for( t = tpostbl[ index ]; t != NULL; t = t->tlink )
  134.         (*func)( t, arg );
  135.       }
  136.  
  137.     if( other_t != NULL )
  138.       {
  139.     for( t = other_t->x.ptr; t != other_t; t = t->x.ptr )
  140.         (*func)( t, arg );
  141.       }
  142.   }
  143.